import { defineStore } from "pinia";
import { store } from '@/store';
import type { ReturnWxShareOptions } from "@/components/CustomShare/types";
import type { IActivityListResData } from "@/api/activity/types";

/**
 * @description 活动详情的分享内容
 * @description 暂存给活动详情的后续流程页面使用
 * @date 07/08/2024
 * @export
 * @interface IActivityShareCache
 */
export interface IActivityShareCache {
  wxShareOptions: ReturnWxShareOptions[];
  shareLogId: number;
  // posterDrawData: string[];
  shareTimelineContent: Page.ShareTimelineContent
  activeityData: Pick<IActivityListResData, 'id' | 'coverUrl' | 'title' | 'startTime' | 'endTime' | 'addressName'>
}

interface ActivityState {
  activityShareCache: IActivityShareCache | null
  /** 活动下单路由参数暂存 */
  activityOrderRouteParams: IActivityListResData | null
}

const createState = (): ActivityState => ({
  activityShareCache: null,
  activityOrderRouteParams: null,
});


export const useActivityStore = defineStore({
  id: 'activity',
  state: () => createState(),
  getters: {
    getActivityShareCache: (state) => state.activityShareCache,
    getActivityOrderRouteParams: (state) => state.activityOrderRouteParams,
  },
  actions: {
    /**
     * @description 活动详情的分享内容暂存, 用于 排行榜
     * @date 13/08/2024
     * @param {IActivityShareCache} data
     */
    setActivityShareCache(data: IActivityShareCache) {
      this.activityShareCache = data;
    },
    /**
     * @description 在活动详情将活动详情暂存, 用于 报名记录 / 选票列表 / 下单页(填写报名信息及支付页面)
     * @date 13/08/2024
     * @param {IActivityListResData} data
     */
    setActivityOrderRouteParams(data: IActivityListResData) {
      this.activityOrderRouteParams = data;
    },
  }
})

export function useActivityWithOut() {
  return useActivityStore(store);
}